package com.contract.spirit.ui.order.adapter

import android.content.Context
import android.view.animation.DecelerateInterpolator
import androidx.viewpager.widget.ViewPager
import com.contract.commonlib.util.ext.setOnSingleClickListener
import com.contract.commonlib.util.CommonUtils
import com.contract.spirit.R
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerIndicator
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView
import net.lucode.hackware.magicindicator.buildins.commonnavigator.indicators.LinePagerIndicator
import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.ColorTransitionPagerTitleView

/**
 * @author: zhengjun
 * created: 2021/9/27
 * desc:
 */
class NavigatorIndicatorAdapter(private var viewpager: ViewPager) : CommonNavigatorAdapter() {
    var titles = arrayOf("保障中", "获得赔付", "赔付成功", "全部")
    override fun getCount(): Int {
        return titles.size
    }

    override fun getTitleView(context: Context?, index: Int): IPagerTitleView {
        val titleView = ColorTransitionPagerTitleView(context)
        titleView.normalColor = CommonUtils.getColor(R.color.color6)
        titleView.selectedColor = CommonUtils.getColor(R.color.mainColorOrange)
        titleView.textSize = 14f
        titleView.text = titles[index]
        titleView.setOnSingleClickListener {
            index.also { viewpager.currentItem = it }
        }
        return titleView
    }

    override fun getIndicator(context: Context?): IPagerIndicator {
        val indicator = LinePagerIndicator(context)
        indicator.mode = LinePagerIndicator.MODE_EXACTLY
        indicator.setColors(CommonUtils.getColor(R.color.mainColorOrange))
        indicator.lineHeight = CommonUtils.getDimension(R.dimen.dp_2).toFloat()
        indicator.lineWidth = CommonUtils.getDimension(R.dimen.dp_24).toFloat()
        indicator.roundRadius = CommonUtils.getDimension(R.dimen.dp_1).toFloat()
        indicator.endInterpolator = DecelerateInterpolator(1.6f)
        return indicator
    }
}